<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>唯爱薇o朝圣之路-多级组件继承</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.0.2/vue.global.js"></script>
</head>

<body>
    <div id="app"></div>
</body>
<script>
    const app = Vue.createApp({
        data(){
            return {
                house:'北京别墅一套'
            }
        },
        //provide中提供的值,可以跨代传递
        provide:{
            newHouse: "长沙400平方大平层一套"
        },      
        template: `
            <div>我有一套房子，我先传给我的儿子</div>
            <son :house="house"/>
            <hr />
        `
    })
    app.component('son',{
        props: ['house'],
        template:`
            <div>我是子组件，我要把房子再传给我儿子。</div>
            <br />
            <div><p>儿子接收-{{ house }}-第一级继承</p></div>
            <hr />
            <grandson  :house="house"/>
        `
    })

    app.component('grandson',{
        props: ['house'],
        inject: ['newHouse'],
        template:`
            <div>我是孙子，等待接收房子</div>
            <br />
            <div><p>孙子接收--{{ house }}--第二级继承</p></div>
            <br />
            <div><p>孙子接收--{{ newHouse }}--inject注入,强塞给孙子的</p></div>

        `
    })    
    const vm = app.mount("#app")
</script>